package com.bs.regsystemapi;

import cn.dev33.satoken.SaManager;
import com.bs.regsystemapi.configuration.EnableMybatisPlusConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author: ning
 * @description 启动类
 * @date: 2023/1/2 0:11
 */
@Slf4j
@EnableMybatisPlusConfig
@SpringBootApplication
@EnableAsync
public class RegSystemApiApplication{
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext context = SpringApplication.run(RegSystemApiApplication.class, args);
        Environment env = context.getBean(Environment.class);
        // 获取app的 访问地址
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }

        log.info("项目启动成功...");
        System.out.println("Sa-Token配置如下" + SaManager.getConfig());
        log.info("\n------------------------------------------------------------------\n\t" +
                "Application  is running! Access URLs:\n\t" +
                "Local访问网址: \t\thttp://localhost:" + port + "\n\t" +
                /*"App端访问网址: \t\thttp://localhost:" + port + path + "/front/pages/login.html\n\t" +*/
                "Swagger接口文档访问网址：\thttp://localhost:" + port + path + "/doc.html\n\t" +
                "App端访问地址：\t\thttp://localhost:" + port + path + "/pat/pages/login.html\n\t" +
                "------------------------------------------------------------------");
    }

    //这里配置静态资源文件的路径导包都是默认的直接导入就可以
/*    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pat/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/pat/");
        super.addResourceHandlers(registry);
    }*/
}
